<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 前提  用于查找已定序的数组
    let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    function findEle(arr, target) {
      let start = 0, end = arr.length - 1
      while (start <= end) {
        let middle = Math.floor((start + end) / 2)
        ele = arr[middle]
        if (target === ele) {
          return middle
        } else if (target < ele) {
          end = middle - 1
        } else {
          start = middle + 1
        }
      } return -1
    } console.log(findEle(arr, 11));


  </script>
</body>

</html>